package com.neuedu.service.impl;

import com.neuedu.dao.DongShuDao;
import com.neuedu.dao.impl.DongShuDaoImpl;
import com.neuedu.model.DongShu;
import com.neuedu.model.XiaoQu;
import com.neuedu.service.DongShuService;
import com.neuedu.vo.PageVO;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class DongShuServiceImpl implements DongShuService {
    DongShuDao dongShuDao=new DongShuDaoImpl();
    @Override
    public PageVO<DongShu> selectOnePage(Integer pageNo, Integer pageSize, String startTime, String endTime, String name) {
        Integer limitParams1=(pageNo-1)*pageSize;
        Integer limitParams2=pageSize;
        List<DongShu> dongShus = dongShuDao.selectPageList(limitParams1, limitParams2, startTime, endTime, name);
        int count = dongShuDao.selectCount(startTime, endTime, name);

        PageVO<DongShu> pageVO=new PageVO<>();
        pageVO.setCount(count);
        pageVO.setData(dongShus);
        pageVO.setPageNo(pageNo);
        pageVO.setPageSize(pageSize);
        pageVO.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        return pageVO;
    }

    /**
     * 添加栋数
     */
    public static int number=1;
    @Override
    public int add(DongShu dongShu) {
        //JC20240319001
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        String bianhao="JC"+format;
        if(number<10){
            bianhao=bianhao+"00"+number;
        }else if(number<100){
            bianhao=bianhao+"0"+number;
        }else{
            bianhao=bianhao+number;
        }
        dongShu.setDongshubianhao(bianhao);
        SimpleDateFormat chuangjianshijianSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String chuangjianshijian=chuangjianshijianSdf.format(date);
        dongShu.setChuangjianshijian(chuangjianshijian);

        return dongShuDao.add(dongShu);
    }

    @Override
    public int del(Integer[] ids) {
        return dongShuDao.del(ids);
    }

    @Override
    public DongShu findDongShuById(Integer id) {
        return dongShuDao.selectDongShuOne(id);
    }

    @Override
    public List<DongShu> findDongShuByXiaoquName(String name) {
        List<DongShu> dongShus = dongShuDao.selectDongShuByXiaoQuName(name);
        return dongShus;
    }

    @Override
    public int editDongShuInfo(DongShu dongShu) {
        return dongShuDao.updateDongShu(dongShu);
    }
}
